// import './assets/iconfont/iconfont.css';
import verify from './plugins/Verify.js';
import './assets/js/StringExt.js';
import './assets/js/UUID.js';
import Vue from 'vue';
import VueBus from './plugins/VueBus';
import Ajax from './plugins/Ajax.js';
import store from './store/index';
import Filters from './plugins/Filters.js';
import App from './App.vue';
import router from './router/index';
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
// import './assets/css/icon.css';
import "babel-polyfill";
import './plugins/GlobalComponents';

Vue.prototype.verify = verify;
Vue.use(VueBus);
Vue.use(Filters);
Vue.use(Ajax);
Vue.config.devtools = process.env.NODE_ENV === 'development';
Vue.config.productionTip = false;
Vue.use(ElementUI, {
    size: 'small'
});

window.addEventListener('storage', function (event) {
    if (event.newValue) {
        window.location = top.location.href.substring(0, top.location.href.indexOf('#'));
    }
}, false);


new Vue({
    router,
    store,
    beforeCreate() {
    },
    mounted() {
        //会话失败事件监听
        this.$bus.$on(this.$env.TOKEN_INVALID, () => {
            this.logout();
        });

        //登录退出事件监听
        this.$bus.$on(this.$env.LOGIN_OUT_SUCCESS, () => {
            this.logout();
        });

        //登录成功事件监听
        this.$bus.$on(this.$env.LOGIN_SUCCESS, loginUser => {
            this.login(loginUser);
        });

    },
    destroyed() {
        this.$bus.$off(this.$env.TOKEN_INVALID);
        this.$bus.$off(this.$env.LOGIN_OUT_SUCCESS);
        this.$bus.$off(this.$env.LOGIN_SUCCESS);
    },
    methods: {
        /**
         * 登出处理
         * @author yangjunxiong
         * @date 2019/3/15 10:56
         */
        logout() {
        },
        /**
         * 登录处理
         * @author yangjunxiong
         * @date 2019/3/15 10:57
         */
        login(loginUser) {
            //加载当前用户模块 /当前用户信息
            this.$router.push('/logbackLogIndex');
        }
    },
    render: h => h(App)
}).$mount('#app');